Completed
Push — phpunit ( 7f2080...75f541 )
by Marcos
14:28 queued 10:45
created

PassmanImporter.passmanJson.readFile   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 57

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
c 2
b 0
f 0
nc 1
nop 1
dl 0
loc 57
rs 9.6818

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
// Importers should always start with this
2
var PassmanImporter = PassmanImporter || {};
1 ignored issue
show
Bug introduced by
The variable PassmanImporter seems to be never initialized.
Loading history...
3
(function(window, $, PassmanImporter) {
4
	'use strict';
5
	PassmanImporter.passmanJson = {
6
		info: {
7
			name: 'Passman JSON',
8
			id: 'passmanJson',
9
			description: 'Export the item in passman as passman json, with all fields enabled'
10
		}
11
	};
12
13
	PassmanImporter.passmanJson.readFile = function (file_data) {
14
		return new C_Promise(function(){
0 ignored issues
show
Bug introduced by
The variable C_Promise seems to be never declared. If this is a global, consider adding a /** global: C_Promise */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
15
			var parsed_json = PassmanImporter.readJson(file_data);
16
			var credential_list = [];
17
			for (var i = 0; i < parsed_json.length; i++) {
18
				var item = parsed_json[i];
19
				var _credential = PassmanImporter.newCredential();
20
				_credential.label = item.label;
21
				_credential.username = item.account;
22
				_credential.password = item.password;
23
				_credential.email = item.email;
24
				_credential.url = item.url;
25
				_credential.tags = item.tags;
26
				_credential.description = item.description;
27
				//Check for custom fields
28
				if (item.hasOwnProperty('customFields')) {
29
					//Check for otp
30
					if (item.customFields.length > 0) {
31
						for (var cf = 0; cf < item.customFields.length; cf++) {
32
							_credential.custom_fields.push(
33
								{
34
									'label': item.customFields[cf].label,
35
									'value': item.customFields[cf].value,
36
									'secret': (item.customFields[cf].clicktoshow == '1')
37
								}
38
							)
0 ignored issues
show
Coding Style introduced by
There should be a semicolon.

Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers.

Further Readings:

Loading history...
39
						}
40
					}
41
				}
42
				if (item.hasOwnProperty('otpsecret')) {
43
					if (item.otpsecret) {
44
						_credential.otp = {
45
							'issuer': item.otpsecret.issuer,
46
							'label': item.otpsecret.label,
47
							'qr_uri': {
48
								'image': item.otpsecret.qrCode,
49
								'qrData': ''
50
							},
51
							'secret': item.otpsecret.secret,
52
							'type': item.otpsecret.type
53
						}
0 ignored issues
show
Coding Style introduced by
There should be a semicolon.

Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers.

Further Readings:

Loading history...
54
					}
55
				}
56
				if(_credential.label){
57
					credential_list.push(_credential);
58
				}
59
				var progress = {
60
					percent: i/parsed_json.length*100,
61
					loaded: i,
62
					total: parsed_json.length
63
				};
64
65
				this.call_progress(progress);
66
			}
67
			this.call_then(credential_list);
68
		});
69
	};
70
})(window, $, PassmanImporter);
71